﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using XYAC.Framework.MonitorTireMaterialOnline.OracleRemoteDB;

namespace XYAC.Framework.MonitorTireMaterialOnline.Entities
{
    [Table("WeightData")]
    public class WeightDataLocal : WeightData
    {

        [NotMapped]
        [Obsolete("This property should not be used.", true)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Browsable(false)]
        [JsonIgnore]
        public override bool? IsDeleted { get => base.IsDeleted; set => base.IsDeleted = value; }
        /// <summary>
        /// 同步状态
        /// </summary>
        public bool SyncState { get; set; }
        /// <summary>
        /// 最后同步时间
        /// </summary>
        public DateTime? LastSyncDate { get; set; } = DateTime.Now;
        public static WeightDataLocal From(WeightData data)
        {
            return new()
            {
                ID = data.ID,
                WeightSD = data.WeightSD,
                WeightTolUp = data.WeightTolUp,
                WeightTolDown = data.WeightTolDown,
                WeightAlmUp = data.WeightAlmUp,
                WeightAlmDown = data.WeightAlmDown,
                Weight = data.Weight,
                StartTime = data.StartTime,
                ProfileName = data.ProfileName,
                ProfileType = data.ProfileType,
                BanZu = data.BanZu,
                TestResult = data.TestResult,

                // 初始化 WeightDataLocal 的新属性
                SyncState = false,
                LastSyncDate = DateTime.Now,
            };
        }


        internal YB_PROCESS_STEP ToYB_PROCESS_STEP()
        {
            return new YB_PROCESS_STEP
            {
                RECORD1 = this.ID.ToString(),
                EQP_TYPE = "2",//WeightData数据表特定要求
                RECORD2 = this.WeightSD.ToString("F2"),
                RECORD3 = this.WeightTolUp.ToString("F2"),
                RECORD4 = this.WeightTolDown.ToString("F2"),
                RECORD5 = this.WeightAlmUp.ToString("F2"),
                RECORD6 = this.WeightAlmDown.ToString("F2"),
                RECORD7 = this.Weight.ToString("F2"),
                RECORD_DATE = Convert.ToDateTime(this.StartTime),
                PART_NUMBER = this.ProfileName,
                RECORD8 = this.ProfileType.ToString(),
                RECORD9 = this.BanZu,
                RECORD10 = this.TestResult,
                RECORD29 = "WeightData",


            };
        }
    }
}
